#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: tap_connector_decorator.py 
@version:
@time: 2022/03/05 
"""
# **** decorator  ****
from functools import wraps
from TapUtil.logfunc.logger import logger


def connector_query_logger(robot):
    """
    语句执行装饰圈日志
    :param robot:
    :return:
    """

    @wraps(robot)
    def conLog(*args, **kwargs):
        # if args:
        #     logger.info(f'QUERY >>> {args}')
        # if kwargs:
        #     logger.info(f'QUERY >>> {kwargs}')
        result = robot(*args, **kwargs)
        # logger.info(f'QUERY RESULT is >>> {result}')
        return result

    return conLog


def connector_exec_logger(robot):
    """
    语句执行装饰圈日志
    :param robot:
    :return:
    """

    @wraps(robot)
    def conLog(*args, **kwargs):
        if args:
            logger.info(f'EXEC >>> {args}')
        if kwargs:
            logger.info(f'EXEC >>> {kwargs}')
        result = robot(*args, **kwargs)
        logger.info(f'EXEC RESULT is >>> {result}')
        return result

    return conLog


def generate_logger(robot):
    """
    语句执行装饰圈日志
    :param robot:
    :return:
    """

    @wraps(robot)
    def genLog(*args, **kwargs):
        if args:
            logger.info(f'GENERATE ARGS IS >>> {args}')
        if kwargs:
            logger.info(f'GENERATE KWARGS IS >>> {kwargs}')
        result = robot(*args, **kwargs)
        logger.info(f'GENERATE RESULT IS >>> {result}')
        return result

    return genLog


def not_support(robot):
    @wraps(robot)
    def func(*args, **kwargs):
        raise AttributeError('func can not use')

    return func
